chrome.runtime.sendMessage("tabId",function(message){})

function task(){
	chrome.runtime.sendMessage("getInterval", (message) => {
		if(!message){
			message=240000;//默认4分钟刷新一次
		}
		console.info("YKT->"+message/1000+"s后刷新页面,now:"+new Date().toLocaleString())
		setTimeout(() => {
			location.reload();
		},message)
	})
}
let find = function () {
	let dom = document.querySelector(".tipbar");
	if(!dom){
		console.info("YKT->完全没课")
		task();
	}else{
		console.info("YKT->有课呢")
		dom.click();
		let count = 0;
		setTimeout(function(){
			let $status = $(".status");
			for(let i = 0,len = $status.length; i < len; i++){
				if($($status[i]).text() === "听"){
					console.info("YKT->["+i+"] 是要听的课！")
					$($(".lessonTitle")[i]).trigger("click")
					count++;
					chrome.runtime.sendMessage("start", message => {
						console.info("YKT->已经进入课堂！")
						window.location.href="about:blank";
						window.close();
					})
				}else{
					console.info("YKT->["+i+"] 不是要听的课")
				}
			}
			if(count === 0){
				task();
			}
		},100);
	}
}
setTimeout(find, 1500);

// chrome.runtime.onMessage.addListener(function(message,sender,callback){
// 	if("urlChanged" === message){
// 		location.reload();
// 		console.info("已经进入课堂！")
// 	}
// });